
package gui;

import gui.messagebox.MessageBox;
import gui.messagebox.TournamentLayoutDialog;
import gui.windows.HostWindow;
import gui.windows.MainWindow;
import gui.windows.OptionWindow;
import gui.windows.RegisterWindow;

import java.awt.EventQueue;
import java.io.File;

import javax.swing.filechooser.FileNameExtensionFilter;

import app.AppGlobals;


import network.ChannelData;

import chat.components.ChannelWindow;

import room.Room;
import tournament.Tournament;

public class GUIHandler {
	
	public static RegisterWindow registerWindow;
	public static ChannelWindow channelWindow;
	
	public static void launchRegisterWindow(){
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					RegisterWindow window = new RegisterWindow();
					registerWindow = window;
					window.frmDevpro.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}
	
	public static void launchChannelWindow(final ChannelData[] channels){
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					ChannelWindow window = new ChannelWindow(channels);
					channelWindow = window;
					window.frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}
	
	
	public static void launchMainWindow(){
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					MainWindow window = new MainWindow();
					window.frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}
	
	
	public static void launchLoginFailedDialog(){
		MessageBox.displayMessageBox("Login Failed.");
	}
	
	public static void launchHostingFailedDialog(){
		MessageBox.displayMessageBox("A Room with that password already exists.");
	}
	
	public static boolean launchEnterRoomPWDialog(Room room){
		String password = MessageBox.displayInputBox("Room Password", "Enter room password: ");
		return password == room.roomName;
	}
	
	
	public static void launchRegisterFailedDialog(){
		MessageBox.displayMessageBox("Failed to Register.");
	}
	
	public static void launchWrongPWDialog(){
		MessageBox.displayMessageBox("Incorrect Password.");
	}
	
	public static void launchTournamentLayoutDialog(Tournament tournament){
		final Tournament finTourn = tournament;
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					TournamentLayoutDialog window = new TournamentLayoutDialog(finTourn);
					window.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}
	
	public static void launchRegisterSuccessDialog(){
		MessageBox.displayMessageBox("Account successfully created");
	}
	
	public static void launcherHostWindow(Boolean isRanked){
		final Boolean ranked = isRanked;
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					HostWindow window = new HostWindow();
					window.rankedGame = ranked;
					window.frmHost.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}
	
	public static void launcherOptionWindow(){
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					OptionWindow window = new OptionWindow();
					window.frmHost.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}
	
	public static String launcherRenameDeck(){
		return MessageBox.displayInputBox("Input", "Enter new deck name : ");
	}
	public static String launcherRenameReplay(){
		return MessageBox.displayInputBox("Input", "Enter new replay name : ");
	}
	public static File[] launcherImportDecks(){
		return MessageBox.displayImportDialog("Import Deck(s)",AppGlobals.launcherConfig.launcherDir + "/deck", new FileNameExtensionFilter("YGOPro Deck (*.ydk)", "ydk"), true);
	}
	public static File[] launcherImportReplays(){
		return MessageBox.displayImportDialog("Import Replay(s)",AppGlobals.launcherConfig.launcherDir + "/replay", new FileNameExtensionFilter("YGOPro Deck (*.yrp)", "yrp"), true);
	}


	
}
